package com.pakaroid.android.app;

import android.content.Context;
import android.widget.CompoundButton;

/**
 * 設定ウィジェットの処理
 */
public class SwitchWidget implements CompoundButton.OnCheckedChangeListener {

	Context c;
	
	public SwitchWidget(Context c) {
		this.c = c;
	}
	
	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		switch(buttonView.getId()) {
		case R.id.widgets_wifi:
			// TODO WiFi設定ウィジェットの処理
			if(isChecked != isWiFiOn(c)){
				boolean isWifiEnabled = PakaroidSettingAppWidgetUtil.toggleWifiSetting(c);
				if(isChecked != isWifiEnabled){
					buttonView.setChecked(isWifiEnabled);
				}
			}
			break;
		case R.id.widgets_brightness:
			// TODO 明るさ設定ウィジェットの処理
			if(isChecked != isBrightnessOn(c)){
				boolean isAutoBrightnessEnabled = PakaroidSettingAppWidgetUtil.toggleBrightness(c);
				if(isChecked != isAutoBrightnessEnabled){
					buttonView.setChecked(isAutoBrightnessEnabled);
				}
			}
			break;
		case R.id.widgets_rotation:
			// TODO 回転設定ウィジェットの処理
			if(isChecked != isRotationOn(c)){
				boolean isAutoRotationEnabled = PakaroidSettingAppWidgetUtil.toggleAutoRotation(c);
				if(isChecked != isAutoRotationEnabled){
					buttonView.setChecked(isAutoRotationEnabled);
				}
			}
			break;
		case R.id.widgets_manner:
			// TODO マナーモード設定ウィジェットの処理
			if(isChecked != isMannerOn(c)){
				boolean isMannerMode = PakaroidSettingAppWidgetUtil.toggleMannerMode(c);
				if(isMannerMode != isChecked){
					buttonView.setChecked(isMannerMode);
				}
			}
			break;
		}		
	}		
	
	public static boolean isWiFiOn(Context c){
		return PakaroidSettingAppWidgetUtil.isWifi(c);
	}

	public static boolean isBrightnessOn(Context c){
		return PakaroidSettingAppWidgetUtil.isAutoBrightnessMode(c);
	}

	public static boolean isRotationOn(Context c){
		return PakaroidSettingAppWidgetUtil.isAutoRotation(c);
	}

	public static boolean isMannerOn(Context c){
		return PakaroidSettingAppWidgetUtil.isMannerMode(c);
	}

}
